//
// Created by gogoqiu on 2021/10/19.
//

#ifndef RAPIDSVN_CMAKE_WIFI_MONITOR_H
#define RAPIDSVN_CMAKE_WIFI_MONITOR_H

#include <model/MyTagApp.h>
#include <action_event.hpp>
#include <ids.hpp>
#include <action.hpp>
#include "wx/wx.h"
#include "../include/threaded_worker.hpp"
#include "tracer.hpp"

class WifiMonitorAction: public NormalAction
{
public:
    WifiMonitorAction(MyTagApp *myTagApp, wxWindow *parent1, Tracer * tracer1 );
    bool Prepare() override;
    bool Perform() override;

protected:
    //int len;
private:

    static int respLength;
    static char* responseText;

    void read_msg ( int fd );
    int netlink_notify (  );
    void print_flags ( unsigned flags, unsigned change );
    void print_type ( unsigned type );
    void OnTrigger();

    int SetGitIP( const char* url );

    void refresh();
    int count;

    static size_t accumulate(void* buffer,size_t size,size_t num_mem_byte,void *stream/** ignore **/);
};

/**
 * start the thread_worker
 * tracer
 * how SvnThreadedWorker link with the ui
 * member variable: worker thread
 * ui: build action->perform( action )
 * MainFrame::OnQueryGitIP:
 * auto * normalAction = new QueryGitIpAction( myTagApp, this, "query git ip");
    Perform( normalAction );
   MainFrame::PerformAction ( NormalAction * action )
   //setup the logTracer, then use the thread to perform the action
   m_actionWorker->Perform ( action )
    workThread
    运作基础
   ThreadWorker::WorkThread
   action->prepare
   设置当前action
   非actionList,逐个执行
   /media/gogoqiu/Data/init/git_oschina/apps/tunnel/linux/networkmessagelistener.cpp
 */
class WifiMonitor: public wxThread {
    wxWindow * parent;
    Tracer * tracer;
    ActionState state;
    ActionResult result;
    MyTagApp* myTagApp;

    NormalAction *action;

public:
    /*
     * ui改善
     */
    explicit WifiMonitor(MyTagApp* myTagApp1, wxWindow* parent,
                         Tracer * tracer, NormalAction* action1 ){
        this->myTagApp = myTagApp1;
        this->parent = parent;
        this->tracer = tracer;
        this->action = action1;
    }

    //
    void * Entry() override;

    //ActionEvent action;
    void ExecuteAction();

    void DeleteAction();

    void TraceError ( const wxString & message ) const;

};


#endif //RAPIDSVN_CMAKE_WIFI_MONITOR_H
